home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / AmigaTalk_X / general / Object.st < prev    next >
Encoding:
Text File  |  2002-03-13  |  3.4 KB  |  133 lines

  1. "-----------------------------------------------------------------"
  2. " Object Class is the Root of all other Classes in AmigaTalk.     "
  3. "-----------------------------------------------------------------"
  4.  
  5. Class Object
  6. [
  7.     == anObject
  8.       ^ <primitive 7 self anObject >
  9. |
  10.     ~~ x
  11.       ^ (self == x) not
  12. |
  13.     = x
  14.       ^ (self == x)              "Is the receiver equal to x??"
  15. |
  16.     ~= x
  17.       ^ (self = x) not           "Is the receiver NOT equal to x??"
  18. |
  19.     asString
  20.       ^ <primitive 152 (self class)> "Avoid recursion!"
  21.       "^ self class printString" "<<--Infinite recursive method."
  22. |
  23.     asSymbol
  24.       ^ self asString asSymbol   "Return the class a Symbol."
  25. |
  26.     yourself                     "Synonym for self."
  27.       ^ self
  28. |
  29.     class
  30.       ^ <primitive 1 self>
  31. |
  32.     copy
  33.       ^ self shallowCopy
  34. |
  35.     deepCopy  ! size newobj !
  36.       size <- <primitive 4 self>.
  37.  
  38.       (size < 0) 
  39.           ifTrue: [^ self] "if special just copy object"
  40.          ifFalse: [ newobj <- self class new.
  41.  
  42.                     (1 to: size) do: [:i |
  43.                       <primitive 112 newobj i ( <primitive 111 self i > copy ) > ].
  44.                     ^ newobj 
  45.                   ]
  46. |
  47.     first
  48.       ^ self
  49. |
  50.     do: aBlock     ! item !
  51.       item <- self first.
  52.  
  53.       ^ [item notNil] whileTrue:
  54.                       [aBlock value: item.  item <- self next]
  55. |
  56.     do: aBlock without: anObject ! item !  "Added on 20-Jun-2001 (JTS)"
  57.       (anObject == nil)
  58.          ifFalse: [ item <- self first.
  59.                     ^ [item notNil] 
  60.                         whileTrue: [ (item ~~ anObject) 
  61.                                        ifTrue: [aBlock value: item].
  62.                        
  63.                                      item <- self next 
  64.                                    ]
  65.                   ]
  66.                   
  67.           ifTrue: [ self do: aBlock ]
  68. |
  69.     error: aString
  70.       <primitive 122 aString self>
  71. |
  72.     isKindOf: aClass ! objectClass !
  73.       objectClass <- self class.
  74.  
  75.       [objectClass notNil] whileTrue:
  76.              [(objectClass == aClass) ifTrue: [^ true].
  77.  
  78.                  objectClass <- objectClass superClass].
  79.       ^ false
  80. |
  81.     isMemberOf: aClass
  82.        ^ aClass == self class
  83. |
  84.     isNil
  85.        ^ false
  86. |
  87.     next
  88.        ^ nil
  89. |
  90.     notNil
  91.        ^ true
  92. |
  93.     print
  94.        <primitive 121 (self printString)>
  95. |
  96.     printNoReturn
  97.        <primitive 120 (self printString)>
  98. |
  99.     printString
  100.        ^ self asString
  101. |    
  102.     respondsTo: cmd
  103.        ^ self class respondsTo: cmd
  104. |    
  105.     shallowCopy ! size newobj !
  106.        size <- <primitive 4 self>.
  107.  
  108.        (size < 0) 
  109.          ifTrue: [^ self] "if special just copy object"
  110.          ifFalse: [ newobj <- self class new.
  111.  
  112.        (1 to: size) do: [:i |
  113.                <primitive 112 newobj i <primitive 111 self i > > ].
  114.  
  115.                           ^ newobj ]
  116. |
  117.    subclassResponsibility: methodString ! msg !
  118.      msg <- String new: 'Method ',methodString,' should be implemented in a SubClass!'.
  119.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'>
  120. |
  121.    notImplemented: methodString ! msg ! 
  122.      msg <- String new: 'Method ',methodString,' NOT implemented!'.
  123.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'>
  124. |
  125.    doesNotUnderstand: methodString ! msg !
  126.      msg <- String new: 'Method ',methodString,' NOT understood!'.
  127.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'> 
  128. |
  129.    shouldNotImplement: methodString ! msg !
  130.      msg <- String new: 'Method ',methodString,' should NOT BE implemented!'.
  131.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'>
  132. ]
  133.